package com.ww.common;

import lombok.Builder;
import lombok.Data;

/**
 * 做统一返回的工具类
 */

@Data
@Builder
public class R {

    /**
     * 自定义常量
     */
    public static final int CODE_ERROR = 10000;
    public static final int CODE_SUCCESS = 20000;
    public static final int CODE_ADMIN = 30001;
    public static final String MSG_ERROR = "操作出错";
    public static final String MSG_SUCCESS = "操作成功";


    private Integer code;

    /**
     * 附加信息
     */
    private String message;

    /**
     * 响应的数据
     */
    private Object data;

    public static R success(){
        return R.builder().code(R.CODE_SUCCESS).message(R.MSG_SUCCESS).build();
    }

    public static R success(Object data){
        return R.builder().code(R.CODE_SUCCESS).message(R.MSG_SUCCESS).data(data).build();
    }

    public static R fail(){
        return R.builder().code(R.CODE_ERROR).message(R.MSG_ERROR).build();
    }

    public static R fail(Object data){
        return R.builder().code(R.CODE_ERROR).message(R.MSG_ERROR).data(data).build();
    }

}
